package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

//
func copyFile(destFileName string, srcFileName string) (written int64, err error) {
	srcFile, err := os.Open(srcFileName)
	if err != nil {
		fmt.Println("err")
	}
	defer srcFile.Close()
	//通过srcFileName，获取reader
	reader := bufio.NewReader(srcFile)
	destFile, err := os.OpenFile(destFileName, os.O_WRONLY|os.O_CREATE, 0666)
	/*通过destFile获取writer*/
	writer := bufio.NewWriter(destFile)
	defer destFile.Close()
	return io.Copy(writer, reader)
}
func main() {
	srcFileName := ""
	destFileName := ""
	fmt.Println("请输入源文件路径")
	fmt.Scanln(&srcFileName)
	fmt.Println("请输入目标文件路径")
	fmt.Scanln(&destFileName)
	_, err := copyFile(destFileName, srcFileName)
	if err != nil {
		fmt.Println("copy failed")
	}
	fmt.Println("copy success")
}
